#pragma once
#include <QString>

namespace ns_yht
{
    namespace FileType
    {
        const int App = 0;  // 应用程序
        const int Emap = 1; // 电子海图

    }

    enum class VersionScanResult
    {
        Unknown = 0,      // 未检测
        NoNeedUpdate = 1, // 检测结束，不需要更新
        NeedUpdate = 2,   // 检测结束，需要更新
        Error = -1        // 检测结束，错误
    };

    struct ModelVersion
    {
        int major{0};
        int minor{0};
        int patch{0};
        int tweak{0};

        // 重写大小比较操作符
        bool operator<(const ModelVersion &other) const
        {
            if (major < other.major)
                return true;
            else if (major == other.major && minor < other.minor)
                return true;
            else if (major == other.major && minor == other.minor && patch < other.patch)
                return true;
            else if (major == other.major && minor == other.minor && patch == other.patch && tweak < other.tweak)
                return true;
            else
                return false;
        }

        bool operator==(const ModelVersion &other) const
        {
            if (major == other.major && minor == other.minor && patch == other.patch && tweak == other.tweak)
                return true;
            else
                return false;
        }

        bool operator>(const ModelVersion &other) const
        {
            if (major > other.major)
                return true;
            else if (major == other.major && minor > other.minor)
                return true;
            else if (major == other.major && minor == other.minor && patch > other.patch)
                return true;
            else if (major == other.major && minor == other.minor && patch == other.patch && tweak > other.tweak)
                return true;
            else
                return false;
        }

        void setVersion(const QString &version)
        {
            QStringList vlist = version.split('.');
            if (vlist.count() > 0)
                major = vlist[0].toInt();
            if (vlist.count() > 1)
                minor = vlist[1].toInt();
            if (vlist.count() > 2)
                patch = vlist[2].toInt();
            if (vlist.count() > 3)
                tweak = vlist[3].toInt();
        }

        QString toString() const
        {
            return QString("%1.%2.%3.%4").arg(major).arg(minor).arg(patch).arg(tweak);
        }
    };
    struct ModelFile
    {
        int ID{0};
        int fileType{0};
        QString filePath;
        QString fileName;
        QString displayName;
        int currentVersionNum{0};
        ModelVersion currentVersion;

        QString updateDate;
        QString remark;

        QString remoteFileName;
        int remoteVersionNum{0};
        ModelVersion remoteVersion;
        QString downloadUrl;
        QString remoteFileUpdateDate;
        quint64 fileSize;
        int importance{0};

        bool updated{false};
    };

    struct ModelSoftware
    {
        QString code;
        QString name;
        ModelVersion currentVersion;
        ModelVersion remoteVersion;
        QString versionDescription;
        QString versionDate;
        QString fileName;
        QString url;

        VersionScanResult state{VersionScanResult::Unknown};
        bool updated{false};
    };
}